﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Yipusoft.Account.BLL;
using Yipusoft.Account.Model;
using Yipusoft.Common.BLL;
using Yipusoft.Common.Model;
using Yipusoft.Task.BLL;
using Yipusoft.Task.Model;
using Yipusoft.Evaluate.BLL;
using Yipusoft.Evaluate.Model;
using System.Data;


public partial class Evaluate_BaseViewD : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindGrid();
        }
    }

    private string GetDepartmentName(string departmentID)
    {

        if (string.IsNullOrEmpty(departmentID))
            return "";
        if (departmentID.Length == 7)
            return Yipusoft.Account.BLL.Department.GetDepartment(departmentID).FullName;

        if (departmentID.Length == 5)
            return Yipusoft.Account.BLL.Department.GetDepartment(departmentID.Substring(0, 4) + "000").FullName;

        if (departmentID.Length == 4)
            return Yipusoft.Account.BLL.Department.GetDepartment(departmentID.Substring(0, 4) + "000").FullName;

        if (departmentID.Length == 6)
            return Yipusoft.Account.BLL.Department.GetDepartment(departmentID + "0").FullName;

        return "";

    }

    private int GetGroupByLen()
    {
        List<RoleInfo> list = Yipusoft.Account.BLL.User.GetRoleList(Yipusoft.Account.BLL.User.GetUser(User.Identity.Name).UserID);

        //是否是司政后防管理员
        bool Flag = list.Where(o => o.RoleID.Equals("100110")).Count() > 0;
        if (Flag)
        {
            return 4;
        }
        else
        {
            return 6;
        }
    }

    private void BindGrid()
    {
        string strWhere = "DepartmentID='" + Request.QueryString["DepartmentID"] + "'";

        UserGrid.Caption = "<span>" + Request.QueryString["Year"] + "年基础数据扣分情况统计表（" + GetDepartmentName(Request.QueryString["DepartmentID"]) + "）</span>";

        if (Request.QueryString["EndMonth"] != null && Request.QueryString["EndMonth"] != Request.QueryString["Month"])
        {
            //strWhere = "DepartmentID='" + Request.QueryString["DepartmentID"] + "' and YearValue=" + Request.QueryString["Year"] + " and MonthValue>=" + Request.QueryString["Month"] + " and MonthValue<=" + Request.QueryString["EndMonth"];
            //UserGrid.Caption = "<span>" + Request.QueryString["Year"] + "年" + Request.QueryString["Month"] + "月至" + Request.QueryString["EndMonth"] + "月基础数据扣分情况统计表（" + Department.GetDepartment(Request.QueryString["DepartmentID"]).FullName + "）</span>";
        }
        else
        {
            strWhere = " Departmentid='" + Request["DepartmentId"] + "' and YearValue=" + Request.QueryString["Year"] + "  and BaseId=" + Request["BaseId"];
            UserGrid.Caption = "<span>" + Request.QueryString["Year"] + "年" + Request.QueryString["Month"] + "月至" + Request.QueryString["EndMonth"] + "月基础数据扣分情况统计表（" + GetDepartmentName(Request.QueryString["DepartmentID"]) + "）</span>";
        }

        List<BaseItemInfo> items = BaseItem.GetList(strWhere);
        UserGrid.DataSource = items;
        UserGrid.DataBind();
    }
    protected void UserGrid_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            Label ID = (Label)e.Row.FindControl("ID");
            ID.Text = (e.Row.RowIndex + 1).ToString();
            //当鼠标放上去的时候 先保存当前行的背景颜色 并给附一颜色 
            e.Row.Attributes.Add("onmouseover", "currentcolor=this.style.backgroundColor;this.style.backgroundColor='#F5F5F5',this.style.fontWeight='';");
            //当鼠标离开的时候 将背景颜色还原的以前的颜色 
            e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=currentcolor,this.style.fontWeight='';");
        }
    }
    public string GetBaseName(int baseID)
    {
        return Base.GetBase(baseID).BaseName;
    }
}
